﻿using MengLin.OOP.DesignPattern.ETC;
using MengLin.OOP.DesignPattern.ETS.Evaluator.Abstract;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MengLin.OOP.DesignPattern.ETS.Evaluator.Implements
{
    /// <summary>
    /// 评分树的矩阵节点
    /// 加叶子节点
    /// </summary>
    public class FeatureGroup: AbstractEvaluator
    {
        //评分器容器
        private Dictionary<AbstractEvaluator, int> _evaluatorContainer = new Dictionary<AbstractEvaluator, int>();

        public string FeatureGroupName { get; set; }

        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="featureGroupName"></param>
        public FeatureGroup(string featureGroupName)
        {
            FeatureGroupName = featureGroupName;
        }

        /// <summary>
        /// 矩阵
        /// </summary>
        private Matrix matrix = new Matrix();

        /// <summary>
        /// 去做评分
        /// </summary>
        /// <returns></returns>
        public override Score DoEvaluate()
        {
            int sumU =0;
            int sumI = 0;
            Score returnScore;
            Score score;
            //遍历评分器列表
            foreach (var abstractEvaluator in _evaluatorContainer)
            {
                AbstractEvaluator concreteEvaluator = abstractEvaluator.Key;
                int rank = abstractEvaluator.Value;
                //真正去做评分由容器中的每1个子类决定
                //注：这里用到组合设计模式
                score = concreteEvaluator.DoEvaluate();
                switch (score)
                {
                    case Score.I:
                        sumI += rank;
                        break;
                    case Score.U:
                        sumU += rank;
                        break;
                }
            }
            returnScore = matrix.GetScore(sumI, sumU);

            return returnScore;
        }

        /// <summary>
        /// 增加评分器
        /// 安全模式
        /// </summary>
        /// <param name="abstractEvaluator"></param>
        /// <param name="rank"></param>
        public void AddEvaluator(AbstractEvaluator abstractEvaluator, int rank)
        {
            _evaluatorContainer.Add(abstractEvaluator, rank);
        }

        /// <summary>
        /// 增加矩阵
        /// </summary>
        public void AddMatrixElement(int i, int u, Score score)
        {

        }
    }
}
